<template>
	<!-- 管理门店 -->
	<view class="wp">
		<view class="nav_bar">
			<view class="serch">
				<uni-search-bar class="input" radius="50" placeholder="搜索门店" clearButton="none" cancelButton="none"
					v-model="formData.keyword" @confirm="search" />
				<text class="screen" @click="openScreen">筛选 <text class="yticon icon-you"></text></text>
			</view>
		</view>
		
		<view class="body">
			<!-- <view class=""> -->
				<!-- <view class="li">总营业额<view>{{info.czMoney}}</view></view> -->
				<!-- <view class="li">已补贴<view>{{info.tkMoney}}</view></view> -->
				<!-- <view class="li">剩余可退<view>{{info.useMoney}}</view></view> -->
			<!-- </view> -->
			<!-- <view class="">
				<view class="li">待回收本金<view>{{info.costMoneyNoCheck}}</view></view>
				
				<view class="li" @click="huishoushow">总回收本金▼<view>{{info.costMoneyAll}}</view></view>
				
				<view class="li" v-model="ishuishou" v-if="ishuishou">今日回收<view>{{info.costMoneyCur}}</view></view>
				
				<view class="li" v-if="ishuishou">昨日回收<view>{{info.costMoneyYes}}</view></view>
				
				<view class="li" v-if="ishuishou">本月回收<view>{{info.costMoneyCurMon}}</view></view>
				
				<view class="li" v-if="ishuishou">上月回收<view>{{info.costMoneyPriMon}}</view></view>
				
			</view> -->
			<view class="flex_evenly shop_tab">
				<view class="shop_tab_it" :class="{'shop_tab_it_ac':type==1}" @click="changeType(1)">直推门店({{info.znum}})</view>
				<view class="shop_tab_it" :class="{'shop_tab_it_ac':type==2}" @click="changeType(2)">其它门店({{info.jnum}})</view>
			</view>
			<view class="list_item" v-for="(item,idx) in list" :key="idx">
				<view class="top">
					<image :src="item.logo" mode=""></image>
					<view class="right" @click="$navTo('../shoplist/shopgoods?id='+item.uid)">
						<view class="title">
							<text class="name">{{item.supname}}</text>
							<text class="label">{{item.name}}</text>
						</view>
						<view class="money">
							<view class="m_li">
								<text>今日实收</text>
								<text class="number">{{item.realprice}}</text>
							</view>
							<!-- <view class="m_li">
								<text>预存余额</text>
								<text class="number">{{item.usemoney}}</text>
							</view> -->
						</view>
						<view class="money">
							<view class="m_li">
								<text>近7日消费</text>
								<text class="number">{{item.saleprice}}</text>
							</view>
							<!-- <view class="m_li">
								<text>日均消费</text>
								<text class="number">{{item.dayprice}}</text>
							</view> -->
						</view>
					</view>
				</view>
				<view class="bottom">
					<view class="b_left">
						<text class="b_e" @click.stop="$navTo('/pages/business/personalstores?uid='+item.uid)">修改信息</text>
						<text class="Entry_time">入驻时间{{item.createtime}}</text>
					</view>
					<!-- <view class="number">预估可消费 <text>{{item.daynum}}</text>天</view> -->
					<view class="number" v-if="item.openpay==1" @click.stop="$navTo('/pages/business/collection?uid='+item.uid)">查看收款码></view>
				</view>
				<view class="l_label" style="padding: 10rpx 0 0;">
					<view class="clamp">【线下收款码】</view>
					<view @click="switchSkm(idx,0)" v-if="item.openpay==1">
						<switch checked color="#8615E1" disabled/>
					</view>
					<view @click="switchSkm(idx,1)" v-else>
						<switch color="#8615E1" disabled/>
					</view>
				</view>	
				<!-- <view class="l_label" style="padding: 10rpx 0 0;">
					<view class="clamp">【开启店铺】</view>
					<view @click="switchDp(idx,-1)" v-if="item.paymode==1">
						<switch checked color="#8615E1" disabled/>
					</view>
					<view @click="switchDp(idx,1)" v-else>
						<switch color="#8615E1" disabled/>
					</view>
				</view>	 -->
				<view class="l_label">
					<view class="clamp">【店主】<text class="color_2">({{item.mid}}){{item.supnickname}}</text></view>
				</view>	
				<view class="l_label"  v-if="item.loginmobile!=''&&item.loginmobile!==null">
					<view class="flex_align_center">【店主电话】
						<text class="color_1" @click="phoneCall(item.loginmobile)">{{item.loginmobile}}</text>
						<image v-if="item.loginmobile!=''" src="/static/copy.png" @click="copy(item.loginmobile)" mode="widthFix" style="width: 36rpx;margin-left: 10rpx;"></image>
					</view>
				</view>
				<view class="l_label">
					<view>【排队单数】<text class="color_2">{{item.ranknum}}</text></view>
				</view>	
				<view class="l_label">
					<!-- <view v-if="item.refermid!=0">【推店人】<text class="color_1">{{item.rfnickname}}({{item.refermid}})</text></view> -->
					<!-- <view v-else>【推店人】<text class="color_1">无</text></view> -->
					<view class="clamp">【推店人】<text class="color_1">({{item.salemid}}){{item.salename}}</text></view>
				</view>
				<view class="l_label" v-if="item.salemobile!=''&&item.salemobile!==null">
					<view class="flex_align_center">【推店人电话】
						<text class="color_1" @click="phoneCall(item.salemobile)">{{item.salemobile}}</text>
						<image src="/static/copy.png" @click="copy(item.salemobile)" mode="widthFix" style="width: 36rpx;margin-left: 10rpx;"></image>
					</view>
				</view>
				<view class="l_label">
					<view>让利<text class="color_1">{{((10 - item.discount) * 10).toFixed(2)}}</text>%</view>
					<!-- <view>售价<text class="color_2">{{item.cusdiscount}}</text></view> -->
					<view>总营业额<text class="color_3">￥{{item.salemoney}}</text></view>
				</view>
				<view class="buttons" v-if="item.showMenu">
					<!-- <text @click.stop="$navTo('../user/dlrecharge?uid='+item.uid)">预存充值</text> -->
					<text v-if="item.status==1" @click.stop="switchDp(idx,-1)">关闭店铺</text>
					<text v-if="item.status==-1" @click.stop="switchDp(idx,1)">开启店铺</text>
					<!-- <text @click.stop="$navTo('../user/setediscount?uid='+item.uid)">设置让利</text> -->
				</view>
			</view>
			<view class="empty">
				<image v-if="isloading" src="../../static/business/loading.gif" mode=""></image>
				<text v-if="!ismore">到底了~</text>
			</view>
		</view>
		<uni-drawer ref="showRight" mode="right" :mask-click="true">
			<scroll-view class="scroll_screen" :scroll-y="true">
				<uni-forms :modelValue="formData" label-width="120px" label-position="top">
					<uni-forms-item label="所属类目">
						<uni-data-select v-model="formData.industry" :localdata="info.industrys"
							:clear="false"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="推店人">
						<uni-data-select v-model="formData.salemid" :localdata="info.salemans"
							:clear="false"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="入驻起始日期">
						<view class="data_time" @click="openPicker('begintime')">
							<text v-if="formData.begintime">{{formData.begintime}}</text>
							<text v-else>选择日期</text>
						</view>
					</uni-forms-item>
					<uni-forms-item label="入驻截止日期">
						<view class="data_time" @click="openPicker('endtime')">
							<text v-if="formData.endtime">{{formData.endtime}}</text>
							<text v-else>选择日期</text>
						</view>
					</uni-forms-item>
					<!-- <uni-forms-item label="实收营业额">
						<uni-easyinput type="number" :clearable="false" v-model="formData.price" placeholder="营业额" />
					</uni-forms-item> -->
					<!-- <uni-forms-item label="预估消费天数">
						<uni-easyinput type="number" :clearable="false" v-model="formData.saleday" placeholder="消费天数" />
					</uni-forms-item> -->
					<!-- <uni-forms-item label="剩余额度">
						<uni-easyinput type="number" :clearable="false" v-model="formData.usemoney"
							placeholder="剩余额度" />
					</uni-forms-item> -->
					<!-- <uni-forms-item label="利润折扣">
						<uni-easyinput type="number" :clearable="false" v-model="formData.discount"
							placeholder="利润折扣" />
					</uni-forms-item> -->
					<view class="screen_submit">
						<button @click="screenSubmit">确定筛选</button>
					</view>
					<view class="block"></view>
				</uni-forms>
			</scroll-view>
		</uni-drawer>
		<simple-datetime-picker ref="myPicker" :startYear="2023" :isd="true" @submit="handleSubmit"></simple-datetime-picker>
	</view>
</template>

<script>
	import SimpleDateTimePicker from '@/components/simple-datetime-picker/simple-datetime-picker.vue'
	export default {
		components: {
			SimpleDateTimePicker
		},
		data() {
			let date = new Date(),
				year = date.getFullYear();
			return {
				endYear: year,
				setDataTime: '',
				formData: {
					industry: '',
					salemid: '',
					begintime: '',
					endtime: '',
					price: '',
					saleday: '',
					usemoney: '',
					discount: '',
					keyword: '',
				},
				info: {
					useMoney:'',
					tkMoney:'',
					czMoney:'',
					costMoneyNoCheck:'',
					costMoneyAll:'',
					costMoneyCur:'',
					costMoneyCurMon:'',
					costMoneyPriMon:'',
					costMoneyYes:'',
					industrys: [{
						value: '',
						text: "全部"
					}],
					salemans: [{
						value: '',
						text: "全部"
					}],
					num: "0"
				},
				page: 0,
				list: [],
				isloading: false,
				ismore: true,
				ishuishou: false,
				type: 1,
			}
		},
		onLoad() {
			this.getInfo();
			this.getList();
		},
		// onShow() {
		// 	this.page = 0;
		// 	this.list = [];
		// 	this.getList();
		// },
		onReachBottom() {
			this.getList();
		},
		methods: {
			changeType(id){
				if(id==this.type) return;
				this.type = id;
				this.page = 0;
				this.list = [];
				this.getList();
			},
			switchSkm(idx,status){
				if(status==1){
					uni.showModal({
						title: '提示',
						content: '首次打开开关将消耗一个门店系统，是否确认打开？',
						success: res=> {
							if (res.confirm) {
								this.realOpenSkm(idx,status)
							}
						}
					});
				}else{
					this.realOpenSkm(idx,status)
				}
			},
			realOpenSkm(idx,status){
				this.$axios('signing/setopenpay','POST','member',{
					uid: this.list[idx].uid,
					status: status,
				}).then(res=>{
					if(res.data.code == 200){
						this.list[idx].openpay = status;
						this.$api.msg(res.data.data);
					}
				})
			},
			switchDp(idx,status){
				this.$axios('signing/setopenShop','POST','member',{
					uid: this.list[idx].uid,
					status: status,
				}).then(res=>{
					if(res.data.code == 200){
						this.list[idx].status = status;
						this.$api.msg(res.data.data);
					}
				})
			},
			phoneCall(v) {
				uni.makePhoneCall({
					phoneNumber: v
				})
			},
			copy(v){
				uni.setClipboardData({
					data: v
				})
			},
			getInfo() {
				this.$axios('signing/mainCheck', 'POST', 'member', this.formData).then(res => {
					if (res.data.code == 200) {
						// this.info.useMoney = res.data.data.useMoney;
						// this.info.tkMoney = res.data.data.tkMoney;
						// this.info.czMoney = res.data.data.czMoney;
						// this.info.costMoneyAll = res.data.data.costMoneyAll;
						// this.info.costMoneyCur = res.data.data.costMoneyCur;
						// this.info.costMoneyCurMon = res.data.data.costMoneyCurMon;	
						// this.info.costMoneyNoCheck = res.data.data.costMoneyNoCheck;
						// this.info.costMoneyPriMon = res.data.data.costMoneyPriMon;
						// this.info.costMoneyYes = res.data.data.costMoneyYes;	
						this.info = res.data.data;
						let obj = res.data.data.industrys.map(v => ({
							value: v.id,
							text: v.name
						}))
						this.info.industrys = [...this.info.industrys, ...obj];
						let obj1 = res.data.data.salemans.map(v => ({
							value: v.id,
							text: v.nickname
						}))
						this.info.salemans = [...this.info.salemans, ...obj1];
					}
				})
			},
			getList() {
				this.page++;
				let obj = {
					...this.formData,
					page: this.page,
					type: this.type
				}
				this.isloading = true;
				this.ismore = true;
				this.$axios('signing/listsCheck', 'POST', 'member', obj).then(res => {
					this.isloading = false;
					if (res.data.code == 200) {
						this.list = [...this.list, ...res.data.data];
						this.ismore = res.data.data.length > 0;
					}
				})
			},
			search() {
				this.page = 0;
				this.list = [];
				this.getList();
			},
			openScreen() {
				this.$refs.showRight.open();
			},
			screenSubmit() {
				this.$refs.showRight.close();
				this.search();
			},
			handleSubmit(e) {
				if (!this.setDataTime) return;
				this.formData[this.setDataTime] = `${e.year}-${e.month}-${e.day}`;
			},
			openPicker(v) {
				this.setDataTime = v;
				this.$refs.myPicker.show();
			},
			huishoushow(){
				if (this.ishuishou == false){
					this.ishuishou = true;
				}else if(this.ishuishou == true){
					this.ishuishou = false;
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f2f2f2;
		color: #303133;
	}

	.wp {
		letter-spacing: 1px;
	}

	.nav_bar {
		background: #fff;
		position: fixed;
		top: calc(var(--window-top) + 0rpx);;
		width: 100%;
		z-index: 100;

		.serch {
			display: flex;
			align-items: center;

			.input {
				flex: 1;
			}

			.screen {
				font-size: 32upx;
				padding-right: 10px;

				text {
					display: inline-block;
					transform: rotateZ(90deg);
				}
			}
		}

		.number {
			font-weight: bold;
			line-height: 24px;
			padding: 0 10px 10px;
		}
	}
	.shell_detailed {
		font-size: 26upx;
		color:#f03201 ;
		font-weight: bold;
		// right: 10upx;
		// left: 10upx;
		padding: 10upx 30upx 10upx 30upx;
		display: flex;
		// justify-content:space-around;	
		justify-content: space-between;
		// vertical-align:middle;
	}
	
	.body {
		// padding: 100px 0;
		padding: 66px 0;
		.shop_tab{
			background: #fff;
			margin: 0 0 20rpx;
			padding: 20rpx 0;
			.shop_tab_it{
				line-height: 52rpx;
				border-radius: 26rpx;
				background: #F0E1FF;
				color: #8615E1;
				padding: 0 20rpx;
			}
			.shop_tab_it_ac{
				border-radius: 26rpx;
				color: #FFFFFF;
				background: #8615E1;
			}
		}
		.li{
			font-size: 32upx;
			color:#666 ;
			font-weight: bold;
			// right: 10upx;
			// left: 10upx;
			padding-top: 10upx;
			padding-right: 30upx;
			padding-left: 30upx;
			padding-bottom: 10upx;
			display: flex;
			// justify-content:space-around;	
			justify-content: space-between;
			border-bottom: 1px hsl(0, 0%, 87%) solid; 
		}

		.list_item {
			background: #fff;
			border-radius: 15upx;
			margin-bottom: 10px;
			padding: 20upx;

			.top {
				display: flex;

				image {
					border-radius: 15upx;
					height: 135upx;
					width: 135upx;
				}

				.right {
					line-height: 45upx;
					padding-left: 20upx;
					width: calc(100% - 135upx);

					.title {
						color: #000;
						display: flex;
						align-items: center;
						font-size: 32upx;

						.name {
							font-weight: bold;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							padding-right: 20upx;
							width: calc(100% - 155upx);
						}

						.label {
							border: 1px $bg-color solid;
							border-radius: 10upx;
							color: $bg-color;
							flex: 1;
							font-size: 28upx;
							text-align: center;
						}
					}

					.money,
					.m_li {
						color: #666;
						display: flex;
						align-items: center;
						justify-content: space-between;

						.m_li {
							justify-content: flex-start;

							.number {
								color: #000;
							}
						}
					}


				}
			}

			.bottom,
			.b_left {
				color: #666;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			.bottom {
				padding: 10upx 5upx;

				.b_left {
					font-size: 32upx;
					
				}

				.b_e {
					color: #fff;
					    width: 134rpx;
					    background: linear-gradient( 90deg, #A350E8 0%, #4E07A9 100%);
					    font-size: 24rpx;
					    text-align: center;
					    border-radius: 8rpx;
					    padding: 6rpx 0;
					    margin-right: 10rpx;


					// margin: 0upx 5upx 0upx 0upx;
				}

				.number {
					text {
						color: $bg-color;
					}
				}
			}

			.l_label {
				color: #000;
				border-top: 1px #DCDFE6 solid;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 10upx;
				padding: 20upx 0;
				font-size: 26upx;
			}

			.color_1 {
				color: #C00101;
			}

			.color_2 {
				color: #C00101;
			}

			.color_3 {
				color: #C00101;
			}

			.buttons {
				
				background-color: #49027c;
				border-radius: 20upx;
				color: #ffffff;
				display: flex;
				align-items: center;
				justify-content: space-around;
				font-size: 32upx;
				line-height: 60upx;
				// font-weight: bold;
			}
		}
	}

	.scroll_screen {
		height: 100vh;
	}

	.uni-forms {
		padding: 0 20upx;
	}

	.uni-forms .uni-forms-item__label {
		padding-bottom: 0 !important;
	}

	.uni-forms .uni-forms-item {
		margin-bottom: 10px;
	}

	.Entry_time {
		color: #666;
		font-size: 11px;
	}

	.data_time {
		border: 1px solid #e5e5e5;
		border-radius: 4px;
		color: #666;
		font-size: 14px;
		height: 35px;
		line-height: 35px;
		padding: 0 10px;
	}

	.screen_submit {
		padding-top: 50upx;
		text-align: center;

		button {
			background: $bg-color;
			color: #fff;
			line-height: 90upx;
			height: 90upx;
			font-size: 34upx;
			letter-spacing: 1px;
		}
	}

	.block {
		height: 100upx;
	}

	.empty {
		image {
			height: 60upx;
			width: 60upx;
		}

		text-align: center;
		color: #4399fc;
	}
</style>